exports.GridObjectDecoration = GridObject.subclass({
	classname : 'GridObjectDecoration',
	_name: 'Fountain',
	
	_populationLimitAddition: 220,
	
	initialize: function($super, dbModel, virtualItem, objectLayer){
		this._dbModel = dbModel;
		this._virtualItem = virtualItem;
		this._objectLayer = objectLayer;
		
		$super(objectLayer);
		
		this.setGridSize(new Core.Vector(4, 4));
        this.setObjectType(ObjectType["ObjectDecoration"]);
		this._obj = new GL2.Sprite();
		this._baseImage = new GL2.Sprite();
		this._imagePath = './Content/images/Objects/Decorations/Fountain';
		this._baseImage.setImage(this._imagePath+'/1.png', [123,80], [0.5, 1]);
		this._baseImage.setDepth(100);
		this._isAnimatable=true;
		this.setObjectState(ObjectState["ObjectPlacement"]);
		this._obj.addChild(this._baseImage);
		if (dbModel != null){
			this.animate();
		}
	},
	
	hasTimedState: function()
	{
		return false;
	},
		
	animate: function()
	{
		this.theLights = new GL2.Sprite();
		this.theLights.setDepth(102);
		var theLightsAnimation = new GL2.Animation();
		theLightsAnimation.pushFrame(new GL2.Animation.Frame(this._imagePath+'/a.png', 200, [86, 52], [0.5,1], [86/512, 52/128, 86/512, 52/128]));
		//theLightsAnimation.pushFrame(new GL2.Animation.Frame('./Content/images/Objects/Decorations/Fountain/a.png', 200, [84, 52], [0.5,1], [256/512, 0/128, 84/512, 52/128]));
		theLightsAnimation.pushFrame(new GL2.Animation.Frame(this._imagePath+'/a.png', 200, [86, 52], [0.5,1], [172/512, 0/128, 86/512, 52/128]));
		theLightsAnimation.pushFrame(new GL2.Animation.Frame(this._imagePath+'/a.png', 200, [86, 52], [0.5,1], [172/512, 52/128, 86/512, 52/128]));
		theLightsAnimation.pushFrame(new GL2.Animation.Frame(this._imagePath+'/a.png', 200, [86, 52], [0.5,1], [86/512, 0/128, 86/512, 52/128]));
		theLightsAnimation.pushFrame(new GL2.Animation.Frame(this._imagePath+'/a.png', 200, [86, 52], [0.5,1], [0/512, 52/128, 86/512, 52/128]));
		theLightsAnimation.pushFrame(new GL2.Animation.Frame(this._imagePath+'/a.png', 200, [86, 52], [0.5,1], [0/512, 0/128, 86/512, 52/128]));

		this.theLights.setAnimation(theLightsAnimation);
        //this.theLights.setRotation(1);
        //this.theLights.setPosition([8, -5]);
		this.theLights.setPosition([7.5, -8]);
        
        this._obj.addChild(this.theLights);
	},
	
	begin:function()
	{
		if (!(this.objectState() == ObjectState["ObjectPlacement"]))
		{
			return;
		}

		if(this._isAnimatable)
		{
			this.animate();	
		}
//		this.incrementPopLimit();
		this.setObjectState(ObjectState["ObjectReady"]);
//		if (this == GameController.getObjectLayer().getHighLightedObject())
//		 {
//			try
//			{
//				GameController.getWidgetsLayer().getTutorial().nextStep(7);
//			}
//			catch(_exception)
//			{
//				console.log('Logger: Exception: ' + _exception.toString());
//			}
//		}
//		
//		try{
//			var model = this.makeDBObject();
//			TTDbUtil.addDecorationObject(model);
//		}
//		catch(e){
//			console.log('Logger model' +e.toString())
//		}
		
	},
	
	getImagePath: function()
	{
		return this._imagePath;
	},
	
//	incrementPopLimit: function(){
//        var populationLimit = GameController.getWidgetsLayer().getStatusBar().getPopulationLimit();
//        var newPopulationLimit = populationLimit + this._populationLimitAddition;
//        GameController.getWidgetsLayer().getStatusBar().setPopulationLimit(newPopulationLimit);
//	},
	
	sell: function($super)
	{
/*        var populationLimit = GameController.getWidgetsLayer().getStatusBar().getPopulationLimit();
        var newPopulationLimit = populationLimit - this._populationLimitAddition;
        GameController.getWidgetsLayer().getStatusBar().setPopulationLimit(newPopulationLimit);
    	TTDbUtil.removeDecoration(this._dbModel._jsonReference);*/
		$super();
	},
	
	getPopulationLimitAddition: function()
	{
		return this._populationLimitAddition;
	},
	
	
	tap: function($super)
	{
		var objectLayer = this._objectLayer;
		
		if (this == objectLayer.getHighLightedObject()){
			
		}
		else{
			if (!objectLayer.getMultiToolStatus())
			{	
				if (this.objectState() == ObjectState.ObjectDirty)
				{
	        		this.switchToIdle();
	        	}
				else
				{
//					if (!isAttributeWindowOpen)
//					{
//			        	isAttributeWindowOpen = true;
//						//GameController.getGameViewManager().addView(new DecorationAttributeWindow(this));
//					}
				}
			}
		}
		$super();
	},
	
	makeDBObject:function(){
//		try{
//			var newID = TTDbUtil.getNextDecorationID();
//			
//			console.log('Logger: New Decoration ID = '  + newID);
//			
//			var myX = this.getGridLocation().getX();
//			var myY = this.getGridLocation().getY();
//			
//			var decDbModel = new DecorationDbModel(newID, newID, myX, myY, 0);
//			this._dbModel=decDbModel;
//			return decDbModel;
//		}
//		catch(_exception){
//			console.log('Logger Exception: ' + _exception.toString());		
//		}	
	},
	updatePosition:function(){
//		if(!this._dbModel){
//			this._dbModel=this.makeDBObject();
//		}
//		this._dbModel.setX(this.getGridLocation().getX());
//		this._dbModel.setY(this.getGridLocation().getY());
//		TTDbUtil.updateDecoration();
	}
		
});
